package tree.nodeType.numeric;

import java.util.ArrayList;

import pools.PoolsManager;
import tree.Node;
import tree.TreeNodesManager;
import tree.nodeType.Numeric;
/**
 * numeric function node
 *
 */
public abstract class NumericFunction  extends Numeric{
	protected int days;
	public NumericFunction(int sonsNeeded, Node parent,TreeNodesManager treeNodesManager,int depth) {
		super(sonsNeeded, parent,depth);
		days=random.nextInt(200)+1;
		if (treeNodesManager!=null){
			treeNodesManager.addNumericFunctionNode(this);
		}
	}
	
	public NumericFunction(int sonsNeeded, Node parent,TreeNodesManager treeNodesManager,int depth,int days) {
		super(sonsNeeded, parent,depth);		
		this.days=days;
		if (treeNodesManager!=null){
			treeNodesManager.addNumericFunctionNode(this);
		}
	}
	
	@Override
	protected ArrayList<Node> getProperNodesManagerList(
			TreeNodesManager treeNodeManager) {
		return treeNodeManager.getAllNumericFunctionsInTree();
	}
	
	public NumericFunction() {}
	
	@Override
	public Node getRandNodeWithTheSameReturnType(int maxDepth,TreeNodesManager tnm){
		return PoolsManager.get().getRandomNumericFuncNode(getDepth(),maxDepth, getParent(),tnm);
//		Node answer=null;
//		Node parent=getParent();
//		
//		if (parent.isHasConstSon() && sons.size()>1){
//			//parent already has one const son, return random numeric func.
//			answer= PoolsManager.get().getRandomNumericFuncNode(getDepth(),maxDepth, parent,tnm);
//		}else{
//			//parent doesn't have one const son, 50% of getting one now.
//			if (random.nextDouble()>0.5){
//				answer= PoolsManager.get().getRandomNumericFuncNode(getDepth(),maxDepth, parent,tnm);				
//			}else{
//				answer= PoolsManager.get().getRandomConstantNode(parent, tnm, getDepth());
//				parent.setHasConstSon(true);
//			}
//		}
//		return answer;
	}
	
	@Override
	public Node getRandNode(int maxDepth,TreeNodesManager tnm){
		return PoolsManager.get().getRandomNumericFuncNode(getDepth(),maxDepth, getParent(),tnm);
	}
	
	//--functions needed for XML FILE--//
	public int getDays() {
		return days;
	}
	public void setDays(int days) {
		this.days = days;
	}
	//-------------------------------//
}
